import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

const nav = {
  state: {
    index: {
      options: [
        {
          key: "index",
          name: "环境精治",
          to: "/index",
          children: 1
        },
        {
          key: "airRadar",
          name: "在线雷达",
          to: "/airRadar",
          children: 0
        },
        {
          key: "microstation",
          name: "污染漂移",
          to: "/microstation",
          children: 0
        },
        {
          key: "alarm",
          name: "实时预警",
          to: "/alarm",
          children: 0
        },
        {
          key: "pollutionTreatment",
          name: "精细化管理",
          to: "/pollutionTreatment",
          children: 0
        },
        {
          key: "enterprise",
          name: "重点企业",
          to: "/enterprise",
          children: 0
        },
        {
          key: "traffic",
          name: "道路交通",
          to: "/traffic",
          children: 0
        },
        {
          key: "constructionSite",
          name: "在建工地",
          to: "/constructionSite",
          children: 0
        },
        {
          key: "strawBurning",
          name: "秸秆焚烧",
          to: "/strawBurning",
          children: 0
        }
      ]
    },
    environmentalProtection: {
      options: [
        {
          name: "空气雷达",
          to: "/airRadar",
          children: 0
        },
        {
          name: "局地微站",
          to: "/microstation",
          children: 0
        },
        {
          name: "辖区企业",
          to: "/enterprise",
          children: 0
        },
        {
          name: "污染治理",
          to: "/pollutionTreatment",
          children: 0
        },
        {
          name: "报警机制",
          to: "/alarm",
          children: 0
        },
        {
          name: "返回",
          to: "/index",
          children: 1
        }
      ]
    }
  },
  mutations: {},
  actions: {},
  getters: {}
};
let tabs = {
  state: {
    options: [],
    activeKey: "",
    navKey: ""
  },
  mutations: {
    // 设置当前激活的tab
    setActiveKey(state, key) {
      for (let keyWord in activeAndNav) {
        if (key.toLowerCase().indexOf(keyWord.toLowerCase()) !== -1) {
          state.activeKey = keyWord;
          state.options = nav.state["index"].options;
          break;
        }
      }
    }
  },
  actions: {},
  getters: {}
};
let activeAndNav = {
  index: "index",
  environmentalProtection: "index",
  airRadar: "airRadar",
  microstation: "microstation",
  enterprise: "enterprise",
  pollutionTreatment: "pollutionTreatment",
  alarm: "alarm",
  traffic: "traffic",
  constructionSite: "constructionSite",
  strawBurning: "strawBurning"
};

let path = {
  state: {
    airRadar: "/airRadar",
    microstation: "/microstation",
    enterprise: "/enterprise",
    pollutionTreatment: "/pollutionTreatment",
    alarm: "/alarm",
    traffic: "/traffic",
    constructionSite: "/constructionSite",
    strawBurning: "/strawBurning"
  }
};

export default new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  modules: {
    nav: nav,
    tabs: tabs,
    path: path
  },
  plugins: [
    createPersistedState({
      storage: window.sessionStorage
    })
  ]
});
